package com.yunding.house.controller;


import com.yunding.house.pojo.Estate;
import com.yunding.house.service.EstateService;
import com.yunding.house.utils.PageResult;
import com.yunding.house.utils.R;
import com.yunding.house.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 楼盘表 前端控制器
 * </p>
 *
 * @author linyang
 * @since 2019-08-15
 */
@RestController
@RequestMapping("/estate")
public class EstateController  {

    /**
     * CRUD
     */
    @Autowired
    private EstateService estateService;


    @RequestMapping("/save")
    public R save(@RequestBody Estate estate) {
        estateService.save(estate);
        return new R(true, StatusCode.OK, "保存成功");
    }

    @RequestMapping("/del")
    public R del(long id) {
        estateService.del(id);
        return new R(true, StatusCode.OK, "删除成功");
    }

    @RequestMapping("/update")
    public R update(@RequestBody Estate estate) {
        estateService.update(estate);
        return new R(true, StatusCode.OK, "修改成功");
    }

    @RequestMapping("/findAll")
    public R findAll() {
        List<Estate> list = estateService.findAll();
        return new R(true, StatusCode.OK, "查询成功",list);
    }

    /**
     * 条件分页查询
     */
    @RequestMapping("/search")
    public PageResult search(int page, int size , @RequestBody Estate estate )
    {
        return estateService.search(page,size,estate);
    }
}
